package com.songpeng.provider.demo.service;


import business.service.AccountService;
import com.songpeng.provider.demo.dao.AccountDao;
import com.songpeng.provider.demo.model.Account;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public void debit(String userId, int money) {
        synchronized (this) {
            Account account = accountDao.getByUserId( userId );
            if (account != null) {
                account.setMoney( account.getMoney() - money );
            }
            accountDao.updateByPrimaryKeySelective( account );
        }
    }
}
